<template>
	<view class="goods_list">
		<goods-list @goodsItemClick="goDetail" :goods="goods"></goods-list>
		<view class="isOver" v-if="flag">--------商品已经到底啦-----------</view>
	</view>
</template>

<script>
	import goodList from '../../components/goods-list/goods-list.vue'
	export default {
		data() {
			return {
				pageindex:1,
				goods:[],
				flag:false
			}
		},
		components:{"good-list":goodList},
		methods: {
			//获取商品列表数据
			async getGoodsList(callBack){
				const res = await this.$myRuquest({
					url:'/api/getgoods?pageindex='+this.pageindex
					
				})
				this.goods=[...this.goods,...res.data.message]
				callBack && callBack()
				// this.goods=res.data.message
			},
			goDetail(id){
				uni.navigateTo({
					url:'/pages/goods-detail/goods-detail?id='+id
				})
			}
		},
		onLoad(){
			this.getGoodsList()
		},
		onReachBottom(){
			this.pageindex++
			this.getGoodsList()
			if(this.goods.length < 10*this.pageindex) return this.flag=true
		},
		onPullDownRefresh(){
			this.pageindex=1
			this.goods=[]
			this.flag=false
			setTimeout(()=>{
				this.getGoodsList(()=>{
					uni.stopPullDownRefresh()
				})
			},1000)
		}
	}
</script>

<style lang="scss">
	.goods_list{
		background:#eee;
	}
	.isOver{
		width: 100%;
		height: 50px;
		line-height: 50px;
		text-align: center;
		font-size: 20rpx;
	}
</style>
